import uvicorn
from fastapi import FastAPI

async def lifespan(app: FastAPI):
    print("lifespan start")
    yield

    print("lifespan end")

app = FastAPI(lifespan=lifespan)

@app.get("/", operation_id="root")
async def root():
    return {"message": "Hello World"}

@app.get("/weather/{city}", operation_id="get_weather")
async def get_weather(city: str):
    # Simulate a weather API call
    """获取城市天气信息"""

    weather_data = {
        "city": city,
        "temperature": 25,
        "description": "Sunny"
    }
    return weather_data

if __name__ == "__main__":
    workers = 2
    uvicorn.run(
        "api:app",
        host="0.0.0.0", 
        port=8000, 
        workers=workers,
        reload=True
    )
